extends HBoxContainer

@onready var texture_rect: TextureRect = $TextureRect
@onready var label: Label = $Label

var color:Globals.COIN_COLOR

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	GameManager.update_coin_signal.connect(update_info)
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass
	
func initNode():
	if !is_node_ready():
		await ready
	texture_rect.texture = Globals.coin_img[color]
	
func update_info():
	if !is_node_ready():
		await ready
	label.text = str(GameManager.PLAYER.save_coin[color])
	if GameManager.players[0].save_coin[color] == 0:
		queue_free()

func _on_button_pressed() -> void:
	# 删除宝石
	GameManager.players[0].save_coin[color] -= 1
	GameManager.available_gems[color] += 1
	update_info()
	GameManager.update_coin_signal.emit()
	GameManager.update_opt_button.emit()
	if GameManager.players[0].save_coin[color] == 0:
		queue_free()
